package org.example.session;

import org.example.Configuration;
import org.example.mapping.BoundSql;
import org.example.mapping.MappedStatement;
import org.example.mapping.SqlSource;

public class DefaultSqlSession implements SqlSession{


    private final Configuration configuration;

    public DefaultSqlSession(Configuration configuration) {
        this.configuration = configuration;
    }


    @Override
    public <T> T selectOne(String statement) {
        return null;
    }

    @Override
    public <T> T selectOne(String statement, Object parameter) {
        MappedStatement mappedStatement = configuration.getMappedStatement(statement);
        if(mappedStatement == null) {
            throw new RuntimeException("未找到对应的MappedStatement,或未绑定");
        }

        SqlSource sqlSource = mappedStatement.getSqlSource();
        BoundSql boundSql = sqlSource.getBoundSql(parameter);
        String buildSql = boundSql.getBuildSql();

        System.out.println(buildSql);


        return null;
    }

    @Override
    public <T> T getMapper(Class<T> clazz) {
        return configuration.getMapper(clazz,this);
    }
}
